package com.zgkxzx.android.rx.schedule;

import com.zgkxzx.android.rx.Action0;

import java.util.concurrent.Executor;

/**
 * 创建者   zgkxzx
 * 创建日期 2017/12/8.
 * 功能描述 线程调度
 */

public class Scheduler {
    final Executor executor;

    public Scheduler(Executor executor) {
        this.executor = executor;
    }

    public Worker createWorker() {
        return new Worker(executor);
    }

    public static class Worker {
        final Executor executor;

        public Worker(Executor executor) {
            this.executor = executor;
        }

        // 这里接受的是Runnable而不是Action0，其实这没什么关系，主要是懒得自定义函数式接口了。
        public void schedule(final Action0 action0) {
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    action0.call();
                }
            });
        }
    }
}
